<?php
/**
 * Created by andrei
 * Date: 8/2/12
 * Time: 2:49 PM
 */

class Db_Cms_Settings extends Common {
	protected static $tableName = TAB_SETTINGS;
	protected static $dbFields = array(
		'id',
		's_project_id',
		's_title',
		's_key',
		's_content',
		'deleted'
	);

    /**
     * @var Db_Cms_Settings
     */
    public $objectArray;

	public $id;
	public $s_project_id;
	public $s_title;
	public $s_key;
	public $s_content;
	public $deleted;

	function __construct($value=NULL, $fieldName=NULL) {
		parent::__construct($value, $fieldName);
	}

	public static function getSettings() {
		$result = self::$DB->q("SELECT * FROM ?f WHERE deleted = 0 AND s_project_id = ?d", self::$tableName, self::$PROJECT['id']);
		$dataReturn = array();
		while ($data = $result->fetch_assoc()) {
			$dataReturn[$data['s_key']] = $data['s_content'];
			$dataReturn[$data['s_key'] . "_title"] = $data['s_title'];
		}
		return $dataReturn;
	}

	public static function getProjectSettings(){
        $sql = "SELECT `pr`.*,`pr`.`id` AS `pr_id` ,`st`.*, `c`.*, `st`.id AS `s_id` FROM ?f AS `st`
                 INNER JOIN ?f AS `pr` ON `pr`.`id` = `st`.`s_project_id`
                 INNER JOIN ?f AS `c` ON `c`.`id` = `pr`.`pr_country_id`
                 WHERE `pr`.`deleted` = 0 AND `st`.`deleted` = 0;";

		return self::$DB->select($sql, self::$tableName, TAB_PROJECTS, TAB_COUNTRIES);
	}



}
